<?php

if(!defined('OI')) {
			
	print '<h1>Access Error</h1>Sorry, this file can not be accessed directly, this is strictly forbidden!';
	exit();
				
}

class pageHeader extends GenericClass {
	
	const LINE_SPLIT = "\n";
	
	/*
	 * Constructor: Trigger parent
	*/
	public function __construct(DigitalUniversity &$digitalUniversity, &$arguments = array()) {
		
		parent::__construct($digitalUniversity, $arguments);
				
		# Clean memory
		unset($digitalUniversity, $arguments);
		
		# Head tag contents
		$this->pageHeadTag();
		$this->pageBodyTag();
		
	}
	
	/*
	 * Destructor: Trigger parent
	*/
	public function __destruct() {
		
		parent::__destruct();
		
	}
	
	/*
	 * getSiteTitle: Detect the current page title and output the title
	 *
	 * @return String $siteTitle - String containing the title
	*/
	private function getSiteTitle() {
	
		if(!empty($this->digitalUniversity->pageDetails)) {
			$siteTitle = $this->digitalUniversity->pageDetails['p_title'].' &middot; '.$this->digitalUniversity->config['siteTitle'];
		} else {
			$siteTitle = $this->digitalUniversity->config['siteTitle'];
		}
		
		return $siteTitle;
		
	}
	
	private function pageHeadTag() {
		
echo '<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>'.$this->getSiteTitle().'</title>
<!--[if IE]>
	<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<!-- HTML5 Reset -->
<link rel="stylesheet" href="{config-root_url}template/css/resetHTML5.css" />

<!-- Page styles -->
<link rel="stylesheet" type="text/css" href="{config-root_url}template/css/?2" />

<!-- jQuery scripts -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="{config-root_url}javascript/?2"></script>

<!-- Favicon -->
<link rel="Shortcut Icon" href="{config-root_url}favicon.ico" />';

		# Line split
		echo self::LINE_SPLIT;

		# Close head tag
		echo '</head>';

	}
		
	private function pageBodyTag() {
	
		# Open body tag
		echo self::LINE_SPLIT.'<body class="clearfix">'.self::LINE_SPLIT;
				
		# Exit if login
		if($this->digitalUniversity->input['page'] == 'login') {
			return;
		}
		
		/*
		<li>
			<a href="#">second</a>
			<div class="fillArrow">&nbsp;</div>
			<div class="arrow">&nbsp;</div>					
		</li>
		<li>
			<a href="#">third</a>					
			<div class="fillArrow">&nbsp;</div>
			<div class="arrow">&nbsp;</div>
		</li>
		*/
		
		# User notifications
		$notifications = $this->digitalUniversity->db->getResults("SELECT * FROM users_modules um
		LEFT JOIN modules_news mn ON (um.moduleID = mn.moduleID)
		WHERE um.userID = '{$this->digitalUniversity->user['userID']}'
		ORDER BY mn.time DESC
		LIMIT 5");
				
		# Menu tree
		$tree = $this->digitalUniversity->getPageTree();
		
		# Open page container
		echo '
<header class="clearfix">
	<div class="centerAlign">
		<a href="{config-root_url}" class="homeButton">&nbsp;</a>
		<div class="homeButtonArrow">&nbsp;</div>
		<nav class="siteLocation">
			<ul>';
			
				if(empty($tree)) {
			
					echo '<li>
						<a href="{config-root_url}">'.$this->digitalUniversity->user['firstName'].' '.$this->digitalUniversity->user['surname'].'</a>
						<div class="fillArrow">&nbsp;</div>
						<div class="arrow">&nbsp;</div>					
					</li>';
				
				} else {
				
					foreach($tree as $k => $v) {
					
						echo '<li>
							<a href="'.$v['link'].'">'.$v['title'].'</a>
							<div class="fillArrow">&nbsp;</div>
							<div class="arrow">&nbsp;</div>					
						</li>';
						
					}
					
				}
				
				/*
				<li class="finalArrow">
					<div class="endFill">&nbsp;</div>
				</li>
				*/
				
				echo '
			</ul>
		</nav>    
    	<section class="topSearchBox">
			<form>
				<input class="searchBox" placeholder="search" type="text" value="" id="searchBox" />
				<input class="searchButton" type="submit" value=""  />
  			</form>
		</section>
		<div class="dialog pBxToggle" id="searchResults">
			<div class="searchResults resultsBook">results title results title results title</div>
			<div class="searchResults resultsResource">results title results title results title</div>
		</div>
		<a class="notifications'.(($this->digitalUniversity->user['notifications'] != 0) ? ' newNotifications' : '').'" rel="toggleDialog" data-toggle="notifications" href="{config-scripturl}page=notifications">&nbsp;</a>
		<div class="dialog pBxToggle" id="cBxDialog-notifications">';
			if(!empty($notifications)) {
				foreach($notifications as $k => $v) {
					echo '<div class="announcement">
						<p>'.$v['title'].'</p>
					</div>';	
				}
			} else {
				echo '<div class="announcement">
					<p>There are currently no notifications.</p>
				</div>';
			}			
		echo '</div>
		<a class="settings" rel="toggleDialog" data-toggle="settings" href="{config-scripturl}page=account">&nbsp;</a>
		<div class="dialog pBxToggle" id="cBxDialog-settings">
			<ul class="dropMenu">
				<li><a href="{config-scripturl}page=logout">Logout</a></li>
				<li><a href="{config-scripturl}page=help">Help</a></li>
				<li class="lastChild"><a href="{config-scripturl}page=contact">Contact</a></li>
		  </ul>
		</div>
	</div>
</header>

<!-- Open pageContainer -->
<div class="pageContainer centreAlign clearfix">
		
	<!-- Open pageContents -->
	<section class="pageContents clearfix">'.self::LINE_SPLIT;
				
	}
	
}

?>